package message.visitor.tests;

import junit.framework.Assert;
import message.types.message.RejectedRequest;
import message.types.stalkerstring.GetUserFromNameAnswer;
import message.types.string.GetUserFromNameRequest;
import message.types.unique.EmptyMessage;

import org.junit.Test;

import stalker.Stalker;
import stalker.tester.TesterStalker;
import stalker.user.User;


public class UserManagerVisitorTest {
  
  @Test
  public void test01() throws InterruptedException {
    TesterStalker tester = new TesterStalker();
    
    User usr = User.createUser("siska");
    System.out.println(usr);
    
    Stalker.USER_MANAGER.acceptMessage(new GetUserFromNameRequest(tester, Stalker.USER_MANAGER, "siska"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new GetUserFromNameAnswer(Stalker.USER_MANAGER, tester, User.getUserFromName("siska"), "siska")));
    Thread.sleep(25);
    Stalker.USER_MANAGER.acceptMessage(new GetUserFromNameRequest(tester, Stalker.USER_MANAGER, "yunis"));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(
        new RejectedRequest(
            Stalker.USER_MANAGER, 
            tester, 
            new GetUserFromNameRequest(tester, Stalker.USER_MANAGER, "yunis")
            )
        ));    Thread.sleep(25);
    Stalker.USER_MANAGER.acceptMessage(new RejectedRequest(Stalker.USER_MANAGER, tester, new EmptyMessage()));
    Thread.sleep(25);
    Assert.assertTrue(tester.isMessage(new RejectedRequest(Stalker.USER_MANAGER, tester, new EmptyMessage())));
    Thread.sleep(25);
  }
  
}
